#ifndef MOTORSHOW_H
#define MOTORSHOW_H

#include <QDialog>
#include "uartselect.h"
#include <QMainWindow>
#include <QMessageBox>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QPainter>
#include <QByteArray>
#include <QPaintEvent>
#include <QLabel>
#include <QPalette>
#include <QMouseEvent>
#include <QPushButton>

class MotorShow : public QDialog
{
    Q_OBJECT
public:
    explicit MotorShow(QMainWindow *parent = 0);
    ~MotorShow();
    int getStatus()
    {
        return Status;
    }
private:
    UartSelect *uartselect;
    QSerialPort *Uart;
    bool renewable;
    int delta;//左右偏移量
    QPushButton *stopButton,*leftMoveButton,*rightMoveButton;
    QByteArray Data;
    QLabel * currentSpeed,*targetSpeed,*currentPWM,*numberLabels[11];
    bool readable,clicked;
    int count,countl,countr;
    long long int speedData[4000] = {0},targetData[4000] = {0},pwmData[4000] = {0},sum;
    int Status;
    long long int total;
    unsigned char datas[15];
    QLabel *detailLabel;
    inline float max(float x,float y)
    {
        if (x>y) return x;
        return y;
    }

    //QLabel *current,*s1_5before,*s1before,*s0_5before;


signals:

public slots:
    void getData();
    void renew();
    void renewPause()
    {
        disconnect(stopButton,SIGNAL(clicked(bool)),this,SLOT(renewPause()));
        connect(stopButton,SIGNAL(clicked(bool)),this,SLOT(renewStart()));
        stopButton->setText("继续");
        renewable = false;
        leftMoveButton->setEnabled(true);
        rightMoveButton->setEnabled(true);
    }
    void renewStart()
    {
        connect(stopButton,SIGNAL(clicked(bool)),this,SLOT(renewPause()));
        disconnect(stopButton,SIGNAL(clicked(bool)),this,SLOT(renewStart()));
        stopButton->setText("暂停");
        renewable = true;
        leftMoveButton->setEnabled(false);
        rightMoveButton->setEnabled(false);
    }
    void leftMove();
    void rightMove();

protected:
    void paintEvent(QPaintEvent *event);
    void mouseMoveEvent(QMouseEvent *e);
    void mousePressEvent(QMouseEvent *e);
    void mouseReleaseEvent(QMouseEvent *e);
};

#endif // MOTORSHOW_H
